/**
 * 
 */
package com.fang.www.join.two.three;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

/**
 * @author 王刚
 *
 */
public class Map extends Mapper<LongWritable, Text, UserKey, User> {
	private User outputvalue = new User();
	private UserKey outputkey = new UserKey();
	@Override
	protected void setup(Mapper<LongWritable, Text, UserKey, User>.Context context)
			throws IOException, InterruptedException {
		
	}
	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, UserKey, User>.Context context)
			throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		init();
		String logInfo = value.toString();
		String infos[] = logInfo.split(",");
		String usrId ="";
		String usrName = "";
		String locId = "";
		String locName ="";
		int flag =0;
		int keyid =0;
		if(infos.length==3){//人表
			usrId = infos[0];
			usrName = infos[1];
			locId = infos[2];
			keyid = Integer.parseInt(locId);
			outputkey.setKeyid(keyid);
			outputkey.setPrimary(false);
		}else{//位置表
			locId = infos[0];
			locName = infos[1];
			keyid = Integer.parseInt(locId);
			flag = 1;
			outputkey.setKeyid(keyid);
			outputkey.setPrimary(true);
		}
		outputvalue.setLocalId(locId);
		outputvalue.setLocalName(locName);
		outputvalue.setUsrId(usrId);
		outputvalue.setUsrName(usrName);
		outputvalue.setFlag(flag);
		context.write(outputkey, outputvalue);
	}
	private void init(){
		outputkey.init1111();
		outputvalue.init1111();
	}

	

}
